/**
 * @class   wosh::BundleGenericWorker
 * @brief   
 *
 *
 * class base per i worker classici dei Bundle
 *
 *
 ****************************************************************************
 * @version $Id: BundleGenericWorker.h 2827 2010-08-02 11:01:48Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ThreadWorkerS;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Core_BundleGenericWorker_H__
 #define __WOSH_Core_BundleGenericWorker_H__

 #include <woshDefs.h>
 #include <core/Thread.h>
 #include <core/BundleGeneric.h>
 #include <core/BusConnector.h>
 #include <core/LogContext.h>


namespace wosh {

class BundleGenericWorker : public wosh::ThreadImpl
 {
	WOSH_CLASSNAME(BundleGenericWorker)
	WOSH_CLASS_ABSTRACT(true)

	public:
		/**
		 * @brief   Default constructor, initialize BusConnector and LogContext.
		 * @param bundle [in] owner of the object
		 */
		BundleGenericWorker( BundleGeneric& bundle )
			: ThreadImpl(&bundle, bundle.getName() + ".WorkerThread" ), BusCore(bundle.BusCore), Log(bundle.Log) {
			setThreadListener(&bundle);
		 }
		/**
		 * @brief   Default constructor, initialize BusConnector, LogContext and threads name.
		 * @param bundle [in] owner of the object
		 * @param thread_name [in] name to be assigned to the thread
		 */
		BundleGenericWorker( BundleGeneric& bundle, const std::string& thread_name )
			: ThreadImpl(&bundle, thread_name ), BusCore(bundle.BusCore), Log(bundle.Log) {
			setThreadListener(&bundle);
		 }
		/**
		 * @brief   Constructor with multiple initializer, provided for convenience.
		 * @param busConnector [in] BusConnector reference to be acquired (as BusCore)
		 * @param log [in] LogContext reference to be acquired
		 * @param thread_name [in] name to be assigned to the thread
		 */
		BundleGenericWorker( BusConnector& busConnector, LogContext& log, const std::string& thread_name )
			: ThreadImpl( NULL, thread_name), BusCore(busConnector), Log(log) {
		 }
		/**
		 * @brief  Destructor. Stops the Thread if still running.
		 */
		virtual ~BundleGenericWorker() {
			if ( isThreadRunning() )
				quitThread();
		 }

	protected:
		BusConnector& BusCore;	///< reference to owner's BusCore
		LogContext& Log;			///< reference to owner's Log


}; // class def

}; // namespace wosh

#endif //__WOSH_Core_BundleGenericWorker_H__
